home *** CD-ROM | disk | FTP | other *** search
/ Aminet 19 / Aminet 19 (1997)(GTI - Schatztruhe)[!][Jun 1997].iso / Aminet / dev / mui / MUIPlusPlus.lha / Source / MainHeader / MUI.hpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-03-24  |  9.1 KB  |  227 lines

  1. /***************************************************************************
  2. ** 
  3. ** MUI - MagicUserInterface
  4. ** (c) 1993-1996 Stefan Stuntz
  5. ** 
  6. ** C++ Header File for MUI 3.8 by Nicholas Allen
  7. ** 
  8. ** This header allows the use of MUI through C++ classes instead of using
  9. ** C and BOOPSI. The advantage of this approach is that more errors will
  10. ** be found at compile time and it makes the code easier to read and write.
  11. ** 
  12. ****************************************************************************
  13. ** Creating objects
  14. ****************************************************************************
  15. ** 
  16. ** Objects can be declared in C++ without initializing them by using the
  17. ** following syntax:
  18. ** 
  19. **     CMUI_<class>  object;
  20. ** 
  21. ** For example:
  22. ** 
  23. **     CMUI_Window   myWindow;
  24. ** 
  25. ** Because this does no initialization the muimaster.library does not
  26. ** have to be open at this point. This allows objects to be declared
  27. ** within structures, classes and as global variables without having to
  28. ** initialize them first.
  29. ** 
  30. ** Having declared an object it could be initialized it later using the
  31. ** following syntax:
  32. ** 
  33. **     object = CMUI_<class> (<tags>);
  34. ** 
  35. **     eg:
  36. ** 
  37. **     myWindow = CMUI_Window (MUIA_Window_Title, "A test window",
  38. **                             .
  39. **                             .
  40. **                             .
  41. **                             TAG_DONE);
  42. ** 
  43. ** You can also declare and initialize objects at the same time by using
  44. ** the following syntax:
  45. ** 
  46. **     CMUI_<class>  object (<tags>);
  47. ** 
  48. ** For example:
  49. ** 
  50. **     CMUI_Slider   mySlider (MUIA_Numeric_Min, 1,
  51. **                             MUIA_Numeric_Max, 10,
  52. **                             TAG_DONE);
  53. ** 
  54. ** Versions of muimaster.library after V8 come with the ability to create
  55. ** common objects using MUI_MakeObject(). This can also be done in C++ by
  56. ** specifying the MakeObject parameters instead of the tag list for
  57. ** objects that are supported by MakeObject. For example:
  58. ** 
  59. **     CMUI_Slider     mySlider ("example slider", 0, 100);
  60. **     CMUI_Button     myButton ("_Ok");
  61. **     CMUI_Checkmark  myCheckmark ("example checkmark");
  62. ** 
  63. ** The following classes allow creation of objects in this manner:
  64. ** 
  65. **     Class name              Parameters
  66. **     ----------              ----------
  67. ** 
  68. **     CMUI_Label              STRPTR label, ULONG flags
  69. **     CMUI_Button             STRPTR label
  70. **     CMUI_Checkmark          STRPTR label
  71. **     CMUI_Cycle              STRPTR label, STRPTR *entries
  72. **     CMUI_Radio              STRPTR label, STRPTR *entries
  73. **     CMUI_Slider             STRPTR label, LONG min, LONG max
  74. **     CMUI_String             STRPTR label, LONG maxlen
  75. **     CMUI_HSpace             LONG space
  76. **     CMUI_VSpace             LONG space
  77. **     CMUI_HBar               LONG space
  78. **     CMUI_VBar               LONG space
  79. **     CMUI_Menustrip          struct NewMenu *nm, ULONG flags
  80. **     CMUI_Menuitem           STRPTR label, STRPTR shortcut, ULONG flags, ULONG data
  81. **     CMUI_BarTitle           STRPTR label
  82. **     CMUI_Numericbutton      STRPTR label, LONG min, LONG max, STRPTR format
  83. ** 
  84. ****************************************************************************
  85. ** Disposing objects
  86. ****************************************************************************
  87. ** 
  88. ** When you have finished using an object you need to dispose of it.
  89. ** Normally you will only have to dispose the Application object as this
  90. ** will automatically dispose all of its children. However, if you add
  91. ** and remove objects dynamically to the application then they will need
  92. ** to be disposed when they are removed. To dispose of an object you just
  93. ** call its Dispose method. For example:
  94. ** 
  95. **     myApplication.Dispose();
  96. ** 
  97. ** will dispose of the application object and its children. The same
  98. ** syntax is used to dispose of any kind of object.
  99. ** 
  100. ** If you dispose of an object that is connected to a parent object then
  101. ** when the parent object is disposed it will get disposed twice and this
  102. ** will cause your program to crash. If MUIPlusPlus is in debug mode then
  103. ** an error message will be generated if you try to dispose an object
  104. ** connected to a parent and the object won't be disposed.
  105. ** 
  106. ****************************************************************************
  107. ** Getting and setting attributes
  108. ****************************************************************************
  109. ** 
  110. ** To get an attribute from an object you call the appropriate get member
  111. ** function. The get member function has the same name as the last part
  112. ** of the tag name in MUI. Thus to check if a window is open or not (i.e.
  113. ** get its MUIA_Window_Open attribute) you would write:
  114. ** 
  115. **     if (myWindow.Open())
  116. **     {
  117. **         .
  118. **         .
  119. **         .
  120. **     }
  121. ** 
  122. ** 
  123. ** To set an attribute you call the appropraite set member function. The
  124. ** set member function has the same name as the last part of the tag name
  125. ** in MUI but is peceeded by "Set". The value to set the attribute is
  126. ** passed as a parameter. Thus to open a window object (i.e. set its
  127. ** MUIA_Window_Open attribute to TRUE) you would write:
  128. ** 
  129. **     myWindow.SetOpen(TRUE);
  130. ** 
  131. ****************************************************************************
  132. ** Calling methods
  133. ****************************************************************************
  134. ** 
  135. ** To call a method just call the member function of the object with the
  136. ** same name as the last part of the method tag with the parameters to
  137. ** the method. For example, to call the Jump method for a List object to
  138. ** jump to line 10 you would write:
  139. ** 
  140. **     myList.Jump(10);    // Scroll the 10th line into view
  141. ** 
  142. ** Because of the way BOOPSI has been implemented calling methods that
  143. ** have a variable number of arguments cannot be called in exactly the
  144. ** same way as those with a fixed number of arguments. In MUIPlusPlus you
  145. ** must pass an object called "sva" (meaning Start Variable Args) as the
  146. ** first argument to the method and then any other arguments must follow.
  147. ** For example, the Notify method of an object takes a variable number of
  148. ** arguments. To setup a notification for an application object to return
  149. ** MUIV_Application_ReturnID_Quit when a window object is closed:
  150. ** 
  151. **     window.Notify(sva, MUIA_Window_CloseRequest, TRUE,
  152. **                   app, 2, MUIM_Application_ReturnID,
  153. **                   MUIV_Application_ReturnID_Quit);
  154. ** 
  155. ** The only difference, therefore, is that you must pass "sva" as the
  156. ** first parameter. If you forget to do this then the compiler will
  157. ** object (you will not cause any problems in your program by forgetting
  158. ** to do this- it just won't compile).
  159. ** 
  160. ** 
  161. ***************************************************************************/
  162. #ifndef LIBRARIES_MUI_HPP
  163. #define LIBRARIES_MUI_HPP
  164.  
  165. // Many MUI shortcuts are incompatiable with this header as they have the
  166. // same name as member functions in classes. For this reason they cannot
  167. // be included. Instead, the shortcuts which are compatiable are redefined
  168. // later in this header file.
  169.  
  170. #ifndef MUI_NOSHORTCUTS
  171. #define MUI_NOSHORTCUTS
  172. #endif
  173.  
  174. #ifndef LIBRARIES_MUI_H
  175. #include <libraries/mui.h>
  176. #endif
  177.  
  178. // Include prototypes for MUI and BOOPSI function calls
  179.  
  180. #ifdef __GNUC__
  181. #include <inline/muimaster.h>
  182. #include <inline/intuition.h>
  183. #else
  184. #include <clib/muimaster_protos.h>
  185. #include <clib/intuition_protos.h>
  186. #endif
  187.  
  188. #include <clib/alib_protos.h>
  189.  
  190. // Shortcuts that are compatiable with this header are redefined here.
  191. // The standard MUI <class>Object shortcuts for creating objects
  192. // (eg. WindowObject etc) have been redefined as <class>Obj
  193. // (eg. WindowObj) so as not to conflict with member functions of the
  194. // same name within classes.
  195.  
  196. #ifndef MUIPP_NOSHORTCUTS
  197.  
  198. #define MenustripObj         MUI_NewObject(MUIC_Menustrip
  199. #define MenuObj              MUI_NewObject(MUIC_Menu
  200. #define MenuObjT(name)       MUI_NewObject(MUIC_Menu,MUIA_Menu_Title,name
  201. #define MenuitemObj          MUI_NewObject(MUIC_Menuitem
  202. #define WindowObj            MUI_NewObject(MUIC_Window
  203. #define ImageObj             MUI_NewObject(MUIC_Image
  204. #define BitmapObj            MUI_NewObject(MUIC_Bitmap
  205. #define BodychunkObj         MUI_NewObject(MUIC_Bodychunk
  206. #define NotifyObj            MUI_NewObject(MUIC_Notify
  207. #define ApplicationObj       MUI_NewObject(MUIC_Application
  208. #define TextObj              MUI_NewObject(MUIC_Text
  209. #define RectangleObj         MUI_NewObject(MUIC_Rectangle
  210. #define BalanceObj           MUI_NewObject(MUIC_Balance
  211. #define ListObj              MUI_NewObject(MUIC_List
  212. #define PropObj              MUI_NewObject(MUIC_Prop
  213. #define StringObj            MUI_NewObject(MUIC_String
  214. #define ScrollbarObj         MUI_NewObject(MUIC_Scrollbar
  215. #define ListviewObj          MUI_NewObject(MUIC_Listview
  216. #define RadioObj             MUI_NewObject(MUIC_Radio
  217. #define VolumelistObj        MUI_NewObject(MUIC_Volumelist
  218. #define FloattextObj         MUI_NewObject(MUIC_Floattext
  219. #define DirlistObj           MUI_NewObject(MUIC_Dirlist
  220. #define CycleObj             MUI_NewObject(MUIC_Cycle
  221. #define GaugeObj             MUI_NewObject(MUIC_Gauge
  222. #define ScaleObj             MUI_NewObject(MUIC_Scale
  223. #define NumericObj           MUI_NewObject(MUIC_Numeric
  224. #define SliderObj            MUI_NewObject(MUIC_Slider
  225. #define NumericbuttonObj     MUI_NewObject(MUIC_Numericbutton
  226. #define KnobObj              MUI_NewObject(MUIC_Knob
  227.